package com.gome.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;

@SuppressWarnings("rawtypes")
public class TraceInfo {

	@SuppressWarnings("unused")
	public static void traceInfo(Object obj) {
		
		StringBuffer sb = new StringBuffer();
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		StackTraceElement[] stacks = new Throwable().getStackTrace();
		int stacksLen = stacks.length;
		sb.append(sdf.format(date)).append(" || ").append("class: ").append(stacks[1].getClassName()).append(" -- method: ").append(stacks[1].getMethodName()).append(" -- lineNumber: ")
		.append(stacks[1].getLineNumber());
		String str = null;
		try {
			str = obj.toString();
		} catch (Exception e) {

		}
		System.out.println(sb.toString() + " --> log : " + str);
	}
	
	
	@SuppressWarnings("unused")
	public static void traceInfo(String name,Object value) {
		StringBuffer sb = new StringBuffer();
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		StackTraceElement[] stacks = new Throwable().getStackTrace();
		int stacksLen = stacks.length;
		sb.append(sdf.format(date)).append(" || ").append("class: ").append(stacks[1].getClassName()).append(" -- method: ").append(stacks[1].getMethodName()).append(" -- lineNumber: ")
		.append(stacks[1].getLineNumber());
		String valuestr = null;
		try {
			valuestr = value.toString();
		} catch (Exception e) {

		}
		System.out.println(sb.toString() + " --> log : " +name +" == " + valuestr);
	}

	@SuppressWarnings("unused")
	public static void traceInfo() {
		StringBuffer sb = new StringBuffer();
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		StackTraceElement[] stacks = new Throwable().getStackTrace();
		int stacksLen = stacks.length;
		sb.append(sdf.format(date)).append(" || ").append("class: ").append(stacks[1].getClassName()).append(" -- method: ").append(stacks[1].getMethodName()).append(" -- lineNumber: ")
				.append(stacks[1].getLineNumber());
		System.out.println(sb.toString());
	}
	
	public static Logger trace(Class clas){
		
		final Logger log = LoggerFactory.getLogger(clas);
		return log;
	}

	public static void traceInfo(Class clas, Object obj) {
		final Logger log = LoggerFactory.getLogger(clas);
		String str = null;
		try {
			str = obj.toString();
		} catch (Exception e) {
			str = null;
		}
		log.info(str);
	}

	public static void traceDebug(Class clas, Object obj) {
		final Logger log = LoggerFactory.getLogger(clas);
		String str = null;
		try {
			str = obj.toString();
		} catch (Exception e) {
			str = null;
		}
		
		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
		StatusPrinter.print(lc);
		log.debug(str);
	}

	public static void traceError(Class clas, Object obj) {
		final Logger log = LoggerFactory.getLogger(clas);
		String str = null;
		try {
			str = obj.toString();
		} catch (Exception e) {
			str = null;
		}
		log.error(str);
	}

	public static void traceWarn(Class clas, Object obj) {
		final Logger log = LoggerFactory.getLogger(clas);
		String str = null;
		try {
			str = obj.toString();
		} catch (Exception e) {
			str = null;
		}
		log.warn(str);
	}
	
	public static void traceTrace(Class clas, Object obj) {
		final Logger log = LoggerFactory.getLogger(clas);
		String str = null;
		try {
			str = obj.toString();
		} catch (Exception e) {
			str = null;
		}
		log.trace(str);
	}
	

}
